/**
 * Copyright (C) 2013 Inera AB (http://www.inera.se)
 *
 * This file is part of Inera Certificate Proxy (http://code.google.com/p/inera-certificate-proxy).
 *
 * Inera Certificate Proxy is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Inera Certificate Proxy is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package se.inera.certificate.proxy.filter;

import org.apache.http.client.HttpClient;
import se.inera.certificate.proxy.mappings.Mapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

import static com.google.common.collect.Maps.newHashMap;

/**
 *
 */
public class RequestContextImpl implements RequestContext {

    private ProxyFilter filter;
    private Mapping mapping;

    public RequestContextImpl(Mapping mapping, ProxyFilter filter) {
        this.filter = filter;
        this.mapping = mapping;
    }

    @Override
    public Mapping getMapping() {
        return mapping;
    }

    @Override
    public HttpClient getHttpClient() {
        return filter.getHttpClient();
    }

    @Override
    public Map<String, String> getHeaders(HttpServletRequest httpServletRequest) {
        Map<String, String> headers = newHashMap();
        headers.put("X-Proxy-Original-Mapping-Mapped-From", mapping.getContext());
        headers.put("X-Proxy-Original-Mapping-Mapped-To", mapping.getMappedPath());
        headers.putAll(filter.getHeaders(httpServletRequest));
        return headers;
    }
}
